package cn.bon.schedule.controller;

import cn.bon.schedule.service.RealTimeScheduleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Lc_cL
 * @Date 2024/1/17
 * @Description
 */

/**
 * 用于冲突检测和工时计算
 */
@Tag(name = "刷新")
@RestController
public class AsynRefresh {
    @Resource
    RealTimeScheduleService realTimeScheduleService;


    @PutMapping("/refresh/{scheduPlanId}")
    @Operation(summary = "刷新排班方案的冲突，工时，违规等")
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "fanout.conflict",durable = "true"),
            exchange = @Exchange(name = "bon.detect",type = ExchangeTypes.FANOUT)
    ))
    public void listenDetect(@PathVariable Long scheduPlanId) {
        realTimeScheduleService.refresh(scheduPlanId);
    }
}
